package com.xinqi.modules.course.classmenu.manager.impl;

import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.xinqi.modules.course.classmenu.domain.ClassMenuEntity;
import com.xinqi.modules.course.classmenu.mapper.ClassMenuMapper;
import com.xinqi.modules.course.classmenu.manager.ClassMenuManager;
import com.xinqi.modules.course.classmenu.dto.rsp.ClassMenuResultDTO;
import com.xinqi.modules.course.classmenu.dto.req.ClassMenuQueryDTO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.mybatis.data.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import lombok.RequiredArgsConstructor;
import java.util.List;
import java.util.Objects;

/**
 * 课程中版块设置表管理层实现
 *
 * @author: linkai
 * @date: 2023/10/25
 */
@Service
@RequiredArgsConstructor
public class ClassMenuManagerImpl extends BaseServiceImpl<ClassMenuMapper, ClassMenuEntity> implements ClassMenuManager {

    /** 自定义分页查询 */
    @Override
    public Page<ClassMenuResultDTO> findPage(Page<Object> page, ClassMenuQueryDTO query) {
        return this.baseMapper.findPage(page, query);
    }

    /** 自定义列表查询 */
    @Override
    public List<ClassMenuResultDTO> findList(ClassMenuQueryDTO query) {
        return this.baseMapper.findList(query);
    }

    /** 根据id查询 课程中版块设置表数据 */
    @Override
    public ClassMenuEntity findById(Long id) {
        CommonErrors.BAD_REQUEST.check(Objects.nonNull(id), "ID不能为空");
        return getById(id);
    }

    /** 根据id更新 课程中版块设置表数据，重写 */
    public boolean updateById(ClassMenuEntity entity) {
        return SqlHelper.retBool(getBaseMapper().updateById(entity));
    }

    /** 根据id删除 课程中版块设置表数据 */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(Long id) {
        CommonErrors.BAD_REQUEST.check(Objects.nonNull(id), "ID不能为空");
        return this.removeById(id);
    }

}
